
{
	var newscript = document.createElement('script');
	newscript.setAttribute('type','text/javascript');
	newscript.setAttribute('src','../scripts/std_sys.js');
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(newscript);
	newscript.onload=function(){
		start();
	}
}
var start = function() {
	const params = new URLSearchParams(top.window.location.search);
	let storage = window.localStorage;
	storage.id = params.get("id");
	storage.token = params.get("token");
	storage.font_size = "font-size:45px";
	console.log("url:"+top.window.location);
	if (storage.token == "null") {
		console.log("no token");
		document.getElementById("no_sign").style.display="";
		document.getElementById("sign").style.display="none";
		document.getElementById("add").disabled=true;
		document.getElementById("submit").disabled=true;
	} else {
		console.log("exist token");
		document.getElementById("no_sign").style.display="none";
		document.getElementById("sign").style.display="";
		document.getElementById("id").innerText="帐号:" + storage.id;
		document.getElementById("add").disabled=false;
		document.getElementById("submit").disabled=false;
	}
	console.log("token:" + storage.token);
	var frame = parent.document.getElementsByTagName("frameset")[1];
	console.log("cols:" + frame.cols);
	//set_url("dfsf.h", 23, 'fdsf');
	//if (storage.system == "mobile") {
	if (sys_get_type() == "mobile") {
		document.getElementById("test").innerHTML="mobile";
		frame.cols="0%,100%.0%";
		document.getElementById("table").style = storage.font_size;
		document.getElementById("sys_set").style = storage.font_size;
		document.getElementById("add").style = storage.font_size;
		document.getElementById("submit").style = storage.font_size;
		document.getElementById("reset").style = storage.font_size;
	} else {
		document.getElementById("test").innerHTML="pc";
	}

	//document.getElementById("demo").innerHTML = "id:" + storage.id + "<br>token:" + storage.token;
}
submit.onclick = function(){
	var table = document.getElementById('table');
	var myform = document.getElementById('form1');
	var contractAll = [];
	var rows=table.rows;
	for(var i=0;i<rows.length;i++){
		var contractList = [];
		var cells=rows[i].cells;
		for(var j=0;j<cells.length;j++){   //--循环所有的列
			contractList.push(cells[j].innerHTML);
		}
		contractAll.push(contractList);
	}
	alert(JSON.stringify(contractAll));
	document.getElementById('JSONText').value = JSON.stringify(contractAll);
	var sys_table = document.getElementById('sys_table');
	var contract_sys = [];
	var rows=sys_table.rows;
	for(var i=0;i<rows.length;i++){
		var sysList = [];
		var cells=rows[i].cells;
		for(var j=0;j<cells.length;j++){   //--循环所有的列
			sysList.push(cells[j].innerHTML);
		}
		contract_sys.push(sysList);
	}
	alert(JSON.stringify(contract_sys));
	document.getElementById('sys_input').value = JSON.stringify(contract_sys);
	myform.submit();
}
function add_row(name,obj){
	let storage = window.localStorage;
	var table = document.getElementById(name);
	var rows = table.rows;
	var otr = table.insertRow(1);
	var num = table.rows[0].cells.length;
	var tname = ["id", "start", "end", "time", "num", "contact"];
	if (obj) {
		for(var j=0; j<num;j++){   //--循环所有的列
			if (j == 6) {
				if (obj[j] == storage.id) {//delete
					if (storage.system == "mobile") {
						otr.insertCell(j).innerHTML = 
							"<input type=\"button\" onClick=\"post_table_del('table', '" + 
							obj[0] + 
							"')\" style=\"font-size:50px\" value=\"撤销\"/>"
					} else {
						otr.insertCell(j).innerHTML = 
							"<input type=\"button\" onClick=\"post_table_del('table', '" + 
							obj[0] + 
							"')\" value=\"撤销\"/>"
					}
				} else {//insert
					if (storage.system == "mobile") {
						otr.insertCell(j).innerHTML = 
							"<input type=\"button\" onClick=\"post_table_del('" + 
							obj[0] + 
							"')\" style=" + storage.font_size +" value=\"未定义\"/>"
					} else {
						otr.insertCell(j).innerHTML = 
							"<input type=\"button\" onClick=\"post_table_del('" + 
							obj[0] + 
							"')\" value=\"未定义\"/>"
					}
				}
			} else {
				otr.insertCell(j).innerHTML = obj[j];
			}
		}
	} else {
		otr.insertCell(j).innerHTML = "<td>0</td>";
		for(var j = 1; j < (num - 1); j++){   //--循环所有的列
		//	console.log("tname:" + j + tname[j]);
			if (j == 3) {//time
				otr.insertCell(j).innerHTML =
					//"<td><input id='time' type='time' required/><td>";
					"<td><input type='time' id='time' value='13:58' min='00:01' max='24:59'/><td>";
			} else if (j == 5) {//contact
				otr.insertCell(j).innerHTML = "直接显示注册时联系方式";
			} else {
				otr.insertCell(j).innerHTML = "<td><input id='"+tname[j]+
					"' name='ss'/></td>";
			}
		}
	}
	return otr;
}
submit.onclick = function(){
	var xhttp = new XMLHttpRequest();
	var array = [], a0 = [], obj = {};
	var table, tmp;
	let storage = window.localStorage;
	xhttp.open("post", "driver" , false);
	table = document.getElementById("table");
	array[0] = "0";
	array[1] = document.getElementById("start").value;
	array[2] = document.getElementById("end").value;
	array[3] = document.getElementById("time").value;
	array[4] = document.getElementById("num").value;
	a0[0] = array;
	obj.data = a0;
	obj.operate = "add";
	obj.id = storage.id;
	obj.token = storage.token;
	console.log("obj:" + JSON.stringify(obj));
	xhttp.send(JSON.stringify(obj));
	location.reload();
	//console.log("response:" + xmlhttp.responseText);
	//var myObj = JSON.parse(xmlhttp.responseText);
}

{
	let storage = window.localStorage;
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", "driver", false);
	xmlhttp.send();
	//console.log("response:" + xmlhttp.responseText);
	var myObj = JSON.parse(xmlhttp.responseText);
	var obj, table, tmp;
	//obj = JSON.parse("{\"list\":[[\"33\",\"88\",\"99\",\"02\"],[\"33\",\"87\",\"99\",\"02\"]]}");
	obj = JSON.parse(xmlhttp.responseText);
	sum = obj.result.length;
	for (var i = 1; i < sum; i++) {
		tmp = add_row("table", obj.result[i]);
	}
	
//jump
	//window.location.href="car/driver.htm?token=" + storage.token + "&id=" + storage.id;
}
